<template>
  <div class="jnpf-opts">
    <!--左侧插槽-->
    <slot name="left" />
    <template v-if="isJudgePer">
      <div v-if="type=='org'">
        <el-dropdown>
          <el-button type="primary" icon="el-icon-plus">
            新建<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="addOrUpdateHandle('','company')">新建公司
            </el-dropdown-item>
            <el-dropdown-item @click.native="addOrUpdateHandle()">新建部门</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
      <el-button type="primary" @click="add" icon="el-icon-plus" v-has="addPerCode" v-else>
        {{ addText === '新建' ? $t(`common.addBtn`) : addText }}
      </el-button>

      <el-button type="text" icon="icon-ym icon-ym-btn-download" @click="exportData()" v-has="exportPerCode">导出</el-button>
      <el-button type="text" icon="icon-ym icon-ym-btn-upload" @click="importData()" v-has="importPerCode">导入</el-button>
    </template>
    <template v-else>
      <el-button type="primary" @click="add" icon="el-icon-plus"  v-if="type!='org'">
        {{ addText === '新建' ? $t(`common.addBtn`) : addText }}
      </el-button>
      <span style="margin: 0 8px" class="btn-wrap">
        <el-button type="text" icon="icon-ym icon-ym-btn-download" @click="exportData()">导出</el-button>
      </span>

      <el-button type="text" icon="icon-ym icon-ym-btn-upload" @click="importData()"  >导入</el-button>
    </template>
    <!-- 默认右侧插槽 -->
    <slot />
  </div>
</template>
<script>
export default {
  props: {
    type:{
      type: String,
      default: ''
    },
    refreshText: {
      type: String,
      default: '刷新'
    },
    addText: {
      type: String,
      default: '新建'
    },
    // 刷新加载状态
    loading: {
      type: Boolean,
      default: false
    },
    // 是否展示刷新按钮
    hasRefresh: {
      type: Boolean,
      default: true
    },
    // 新增按钮权限标识
    addPerCode: {
      type: String,
      default: 'btn_add'
    },
    // 是否开启权限判断
    isJudgePer: {
      type: Boolean,
      default: false
    },

    disabled: {
      type: Boolean,
      default: false
    },
    // 新增按钮权限标识
    exportPerCode: {
      type: String,
      default: ''
    },
    // 新增按钮权限标识
    importPerCode: {
      type: String,
      default: ''
    },
  },
  data() {
    return {}
  },
  methods: {
    refresh() {
      this.$emit('refresh')
    },
    add() {
      this.$emit('add')
    },
    exportData() {
      this.$emit('export')
    },
    importData(key) {
      this.$emit('import',key)
    }
  }
}
</script>
<style lang="scss" scoped>
.jnpf-opts {
  display: inline-block;
}
</style>
